package common.entities.enums;

/**
 * 
 * A pattern describes a set of questions. each pattern in this enum has
 * it's own set of parameters and answers.
 * 
 * Patterns are described in Millioner's specification document
 * 
 * @author Yoyo
 */
public enum PATTERN {

	/**
	 * <b>Pattern</b>: ACTOR_PLAYED_IN_MOVIE
	 * <br>
	 * <br>
	 * <b>Parameter type</b>: Movie
	 * <br><br>
	 * <b>Answers type</b>: Actor
	 * <br>
	 */
	ACTOR_PLAYED_IN_MOVIE("Who was the actor that played in the movie %s?", 1, 
			"Who was the actor that played in the movie [movie-title]?","actor_played_in_movie_question","actor_played_in_movie_question,movie WHERE movie_id=movie.id"),
	
			
	/**
	 * <b>Pattern</b>: MOVIE_RELEASED_IN_YEAR
	 * <br>
	 * <br>
	 * <b>Parameter type</b>: Year (Integer)
	 * <br><br>
	 * <b>Answers type</b>: Movie
	 */
	MOVIE_RELEASED_IN_YEAR("Which of the following movies was released in the year %s?", 1, 
			"Which of the following movies was released in the year [year]?","movie_released_in_year_question","movie_released_in_year_question"),
	

	/**
	 * <b>Pattern</b>: MOVIE_ACTOR_NOT_IN
	 * <br>
	 * <br>
	 * <b>Parameter type</b>: Actor
	 * <br><br>
	 * <b>Answers type</b>: Movie
	 */
	MOVIE_ACTOR_IN("In which movie the actor %s appeared in?",1,
			"In which movie the actor [actor-full-name] played in?","movie_actor_in_question","movie_actor_in_question,actor WHERE actor_id=actor.id"),	
			
			
	/**
	 * <b>Pattern</b>: MOVIE_DIRECTED_BY
	 * <br>
	 * <br>
	 * <b>Parameter type</b>: Director
	 * <br><br>
	 * <b>Answers type</b>: Movie
	 */
	MOVIE_DIRECTED_BY("Which of the following movies was directed by %s?",1,
						"Which of the following movies was directed by [director-full-name]?","movie_directed_by_question","movie_directed_by_question,director WHERE director_id=director.id"),
	
	/**
	 * <b>Pattern</b>: GENRE_OF_MOVIE
	 * <br>
	 * <br>
	 * <b>Parameter type</b>: Movie
	 * <br><br>
	 * <b>Answers type</b>: Genre
	 */	
	GENRE_OF_MOVIE("Which of the following genres is a genre of the movie %s?",1,
			"Which of the following genres is a genre of the movie [movie-title]?","genre_of_movie_question","genre_of_movie_question,movie WHERE movie_id=movie.id");
			
			
	
	private final String patternFormat;
	private final String userPatternFormat;
	private final int numOfParameters;
	private final String tableName;
	private final String queryHelper;
	private static final int numberOfPatterns = 5;
	private final int numOfPatterns = numberOfPatterns;
	
	private PATTERN(String patternFormat, int numOfParameters, String userPatternFormat, String tableName, String queryHelper){
		this.patternFormat = patternFormat;
		this.numOfParameters = numOfParameters;
		this.userPatternFormat = userPatternFormat;
		this.tableName = tableName;
		this.queryHelper = queryHelper;
	}
	
	/**
	 * 
	 * @return A format-string used for a question fill-up
	 */
	public String getPatternFormat(){
		return this.patternFormat;
	}
	
	/**
	 * @return the number of parameters of the pattern
	 */
	public int getNumOfParameters() {
		return numOfParameters;
	}

	
	
	/**
	 * @return the userPatternFormat
	 */
	public String getUserPatternFormat() {
		return userPatternFormat;
	}
	
	public int getNumberOfPatterns(){
		return numOfPatterns;
	}
	
	public static int getNumOfPatterns(){
		return numberOfPatterns;
	}
	
	public String getTableName(){
		return tableName;
	}
	
	public String getQueryHelper(){
		return queryHelper;
	}

	public String toString(){
		return this.userPatternFormat;
	}
	
	//TODO - check that works
	/** 
	 * @param parameters - Varargs that contains the fill-ups for the format
	 * @return - A question string composed from the format and parameters.
	 */
	public String fillQuestion(String... parameters){
		
		String question = String.format(this.patternFormat, (Object[])parameters);
		return question;
	}
}
